//
//  Test1.cpp
//  CPPTest
//
//  Created by you5 Yi on 2021/9/3.
//

#include "Test1.hpp"
#include <iostream>

int f(int n)
{
    if (n<=0) throw n;
    int s = 1;
    for (int i=1; i<=n; i++) {
        s *= i;
    }
    return s;
}

void test1()
{
    try {
        std::cout<<"4!="<<f(4)<<std::endl;
        f(-2);
    } catch (int n) {
        std::cout<<"n="<<n<<"! 不能计算n!"<<std::endl;
    } catch (...) {
        std::cout<<"出现异常!"<<std::endl;
    }
    std::cout<<"程序执行结束"<<std::endl;
}
